package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Override
    public List<TbClueTrackRecord> getTrackClue(Long clueId) {
        List<TbClueTrackRecord> trackClue = tbClueTrackRecordMapper.getTrackClue(clueId);
        return trackClue;
    }

    @Override
    public Integer setTrackClue(TbClueTrackRecord tbClueTrackRecord1,TbClue tbClue) throws ParseException {
        //获取当前用户名
        tbClueTrackRecord1.setCreateBy(SecurityUtils.getUsername());
        //获取当前时间
        Date date = new Date();
        String strDateFormat = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(strDateFormat);
        String format = simpleDateFormat.format(date);
        Date parse = simpleDateFormat.parse(format);
        tbClueTrackRecord1.setCreateTime(parse);

        //更改线索状态
        tbClue.setStatus("2");
        tbClue.setId(tbClueTrackRecord1.getClueId());

        Integer integer = tbClueTrackRecordMapper.setTrackClue(tbClueTrackRecord1);
        Integer integer1 = tbClueTrackRecordMapper.updateClue(tbClue);
        if(integer==1 || integer1==1){
            return 1;
        }
        return -1;
    }

}
